package cn.pcManage.shopManage.service.impl;

import cn.common.common.model.ServerResponse;
import cn.common.shop.model.BaseFreightTemplet;
import cn.pcManage.shopManage.dao.FreightTempletMapper;
import cn.pcManage.shopManage.service.IFreightTempletService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FreightTempletService implements IFreightTempletService {
    @Autowired
    FreightTempletMapper freightTempletMapper;
    @Override
    public ServerResponse<?> getFreightTempletList(BaseFreightTemplet templet) {
        Map<String,Object> resultMap=new HashMap<String, Object>(2);
        PageHelper.startPage(templet.getPage(),templet.getLimit());
        List<BaseFreightTemplet> templetList = freightTempletMapper.getFreightTempletList(templet);
        Page<BaseFreightTemplet> freightTempletPage = (Page<BaseFreightTemplet>) templetList;
        resultMap.put("total", freightTempletPage.getTotal());
        resultMap.put("infos", freightTempletPage);
        return ServerResponse.createBySuccess(resultMap);
    }

    @Override
    public ServerResponse<?> updateFreightTemplet(Map<String,Object> maps) {
        freightTempletMapper.updatePrice((List<Integer>)maps.get("ids"),
                Double.parseDouble(maps.get("firstPrice").toString()),
                Double.parseDouble(maps.get("addPrice").toString()));
        return ServerResponse.createBySuccessMessage("操作成功");
    }
}
